package com.youmoula.mtsq

import android.app.Application
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import org.jetbrains.annotations.NotNull

class StickAndroidViewModelFactory(@NotNull val app: Application): ViewModelProvider.AndroidViewModelFactory(app) {

    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        //return super.create(modelClass)
        if (modelClass.isAssignableFrom(ReplyHomeViewModel::class.java)) {
            return try{
                modelClass.getConstructor(Application::class.java)
                    .newInstance(app)
                //return ReplyHomeViewModel(app) as T
            }catch (e:Exception){
                return super.create(modelClass)
            }

        }
        throw IllegalArgumentException("Unknown ViewModel class")
    }
}